//
//  HomeNoLoginPopView.swift
//  IdleFish
//
//  Created by Ben on 2021/10/25.
//

import SwiftUI

// 未登录状态下，首页浮现的登录气泡
struct HomeNoLoginPopView: View {
    
    // 获取loginVM
    @EnvironmentObject var loginVM: UserManagerViewModel
    
    var body: some View {
        Button(action: {
            // 点击登录按钮，弹出登录view
            loginVM.presentLoginView.toggle()
        }, label: {
            HStack(spacing: 6) {
                
                Image("home_signIn")
                    .resize(size: CGSize(width: 50, height: 50), contentModel: .fit)
                   
                
                VStack(alignment: .leading, spacing: 6) {
                    
                    Text("欢迎来到闲鱼~")
                        .font(.system(size: 18, weight: .bold))
                        .foregroundColor(.white)
                    
                    Text("赶快登录打开新世界吧")
                        .font(.system(size: 14))
                        .foregroundColor(.white.opacity(0.6))
                }
                
                Spacer()
                
                Text("马上登录")
                    .font(.system(size: 18, weight: .bold))
                    .foregroundColor(.black)
                    .padding(.horizontal, 10)
                    .padding(.vertical, 6)
                    .background(
                        Capsule().fill(Color(hex: 0xFCE226))
                    )
            }
            .padding(.horizontal, 12)
            .padding(.vertical, 12)
            .frame(width: SCREEN_WIDTH - 30)
            .background(
                RoundedRectangle(cornerRadius: 10)
                    .fill(Color.black.opacity(0.9))
            )
        })
        .offset(y: -50)
        // 刚刚的崩溃莫名其妙，clear项目后恢复
        // 弹出登录界面
        .fullScreenCover(isPresented: $loginVM.presentLoginView, onDismiss: {
            // 登录界面退出会触发的回调
        }, content: {
            // 接下来完成登录界面UI布局
            LoginView()
                .environmentObject(loginVM)
        })
        
    }
}

struct HomeNoLoginPopView_Previews: PreviewProvider {
    static var previews: some View {
        HomeNoLoginPopView()
    }
}
